<?php
/**
 * Created by PhpStorm.
 * User: huyi
 * Date: 2018/1/23
 * 生产者 ， 发送消息
 * 普通的队列
 */
require_once __DIR__ . '../vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

$connection = new AMQPStreamConnection('localhost', 5672, 'huyi', 'huyi123');
$channel    = $connection->channel();

//申明一个队列发送消息
$msg        = "hello world";
$queue_name = 'hello';
$channel->queue_declare($queue_name, false, false, false, false);
$msg = new AMQPMessage($msg);
$channel->basic_publish($msg, '', $queue_name);

//关闭通道  关闭连接
$channel->close();
$connection->close();
